home *** CD-ROM | disk | FTP | other *** search
/ Linux 68k 2000 / Linux 68k 2000.iso / dokus / DNS-HOWTO < prev    next >
Encoding:
Text File  |  1997-06-18  |  60.8 KB  |  1,420 lines

  1.   DNS HOWTO
  2.   Nicolai Langfeldt janl@math.uio.no
  3.   v1.3.2, 3 June 1997
  4.  
  5.   HOWTO become a totally small time DNS admin.
  6.  
  7.   1.  Preamble
  8.  
  9.   Keywords: DNS, bind, named, dialup, ppp, slip, Internet, domain, name,
  10.   hosts, resolving
  11.  
  12.   1.1.  Legal stuff
  13.  
  14.   (C)opyright 1995 Nicolai Langfeldt.  Do not modify without amending
  15.   copyright, distribute freely but retain copyright message.
  16.  
  17.   1.2.  Credits and request for help.
  18.  
  19.   I want to thank Arnt Gulbrandsen who read the drafts to this work
  20.   countless times and provided many useful suggestions.  I also want to
  21.   thank the people that have e-mailed suggestions, and thank you notes.
  22.   Thank you!  You help me keep going at this.
  23.  
  24.   This will never be a finished document, please send me mail about your
  25.   problems and successes, it can make this a better HOWTO.  So please
  26.   send money, comments and/or questions to janl@math.uio.no.  If you
  27.   send E-mail please make sure that the return address is correct, I get
  28.   a lot of E-mail.  Also, please read the ``FAQ'' section before mailing
  29.   me.
  30.  
  31.   If you want to translate this HOWTO please notify me so I can keep
  32.   track of what languages I have been published in :-).
  33.  
  34.   1.3.  Dedication
  35.  
  36.   This HOWTO is dedicated to Anne Line Norheim.  Though she will
  37.   probably never read it since she's not that kind of girl.
  38.  
  39.   2.  Introduction.
  40.  
  41.   What this is and isn't.
  42.  
  43.   For starters, DNS is is the Domain Name System.  The rules that name
  44.   machines and software that maps those names to IP numbers.  This HOWTO
  45.   documents how to define such mappings using a Linux system.  A mapping
  46.   i simply a association between two things, in this case a machine
  47.   name, like ftp.linux.org, and the machines IP number, 199.249.150.4.
  48.  
  49.   DNS is, to the uninitiated (you ;-), one of the more opaque areas of
  50.   network administration.  This HOWTO will try to make a few things
  51.   clearer.  It describes how to set up a simple DNS name server.
  52.   Starting with a caching only server and going on to setting up a
  53.   primary DNS server for a domain.  For more complex setups you can
  54.   check the ``FAQ'' section of this document.  If it's not described
  55.   there you will need to read the Real Documentation.  I'll get back to
  56.   what this Real Documentation consists of in ``the last chapter''.
  57.  
  58.   Before you start on this you should configure your machine so that you
  59.   can telnet in and out of it, and make successfully make all kinds of
  60.   connections to the net, and you should especially be able to do telnet
  61.   127.0.0.1 and get your own machine (test it now!).  You also need a
  62.   good /etc/host.conf (or /etc/nsswitch.conf), /etc/resolv.conf and
  63.   /etc/hosts files as a starting point, since I will not explain their
  64.   function here.  If you don't already have all this set up and working
  65.   the networking/NET-2 HOWTO explains how to set it up.  Read it.
  66.  
  67.   If you're using SLIP or PPP you need that working.  Read the PPP HOWTO
  68.   if it's not.
  69.  
  70.   When I say `your machine' I mean the machine you are trying to set up
  71.   DNS on.  Not any other machine you might have that's involved in your
  72.   networking effort.
  73.  
  74.   I assume you're not behind any kind of firewall that blocks name
  75.   queries.  If you are you will need a special configuration, see the
  76.   section on ``FAQ''.
  77.  
  78.   Name serving on Unix is done by a program called named.  This is a
  79.   part of the bind package which is coordinated by Paul Vixie for The
  80.   Internet Software Consortium.  Named is included in most Linux
  81.   distributions and is usually installed as /usr/sbin/named.  If you
  82.   have a named you can probably use it; if you don't have one you can
  83.   get a binary off a Linux ftp site, or get the latest and greatest
  84.   source from ftp.vix.com:/pub/bind in either the release or testing
  85.   subdirectory, whatever fits your lifestyle best.
  86.  
  87.   DNS is a net-wide database.  Take care about what you put into it.  If
  88.   you put junk into it, you, and others will get junk out of it.  Keep
  89.   your DNS tidy and consistent and you will get good service from it.
  90.   Learn to use it, admin it, debug it and you will be another good admin
  91.   keeping the net from falling to it's knees overloaded by
  92.   mismanagement.
  93.  
  94.   In this document I state flatly a couple of things that are not
  95.   completely true (they are at least half truths though).  All in the
  96.   interest of simplification.  Things will (probably ;-) work if you
  97.   believe what I say.
  98.  
  99.   Tip: Make backup copies of all the files I instruct you to change if
  100.   you already have them, so if after going through this nothing works
  101.   you can get it back to your old, working state.
  102.  
  103.   3.  A caching only name server.
  104.  
  105.   A first stab at DNS config, very useful for dialup users.
  106.  
  107.   A caching only name server will find the answer to name queries and
  108.   remember the answer the next time you need it.
  109.  
  110.   First you need a file called /etc/named.boot.  This is read when named
  111.   starts.  For now it should simply contain:
  112.  
  113.   ______________________________________________________________________
  114.   ;  Boot file for caching only name server
  115.   ;
  116.   directory /var/named
  117.   ;
  118.   ; type          domain                          source file or host
  119.   cache           .                               root.cache
  120.   primary         0.0.127.in-addr.arpa            pz/127.0.0
  121.   ______________________________________________________________________
  122.  
  123.   VERY IMPORTANT: In some versions of this document the file contents
  124.   listed here will have a couple of spaces or a tab before the first non
  125.   blank character. These are not supposed to be in the file.  Delete any
  126.   leading space in the files you cut and paste from this HOWTO.
  127.  
  128.   The `directory' line tells named where to look for files.  All files
  129.   named subsequently will be relative to this.  /var/named is the right
  130.   directory according to the Linux File system Standard.  Thus pz is a
  131.   directory under /var/named, i.e., /var/named/pz.
  132.  
  133.   The file named /var/named/root.cache is named in this.
  134.   /var/named/root.cache should contain this:
  135.  
  136.   ______________________________________________________________________
  137.    .       518400  NS      D.ROOT-SERVERS.NET.
  138.    .       518400  NS      E.ROOT-SERVERS.NET.
  139.    .       518400  NS      I.ROOT-SERVERS.NET.
  140.    .       518400  NS      F.ROOT-SERVERS.NET.
  141.    .       518400  NS      G.ROOT-SERVERS.NET.
  142.    .       518400  NS      A.ROOT-SERVERS.NET.
  143.    .       518400  NS      H.ROOT-SERVERS.NET.
  144.    .       518400  NS      B.ROOT-SERVERS.NET.
  145.    .       518400  NS      C.ROOT-SERVERS.NET.
  146.   ;
  147.   D.ROOT-SERVERS.NET.     3600000 A       128.8.10.90
  148.   E.ROOT-SERVERS.NET.     3600000 A       192.203.230.10
  149.   I.ROOT-SERVERS.NET.     3600000 A       192.36.148.17
  150.   F.ROOT-SERVERS.NET.     3600000 A       192.5.5.241
  151.   G.ROOT-SERVERS.NET.     3600000 A       192.112.36.4
  152.   A.ROOT-SERVERS.NET.     3600000 A       198.41.0.4
  153.   H.ROOT-SERVERS.NET.     3600000 A       128.63.2.53
  154.   B.ROOT-SERVERS.NET.     3600000 A       128.9.0.107
  155.   C.ROOT-SERVERS.NET.     3600000 A       192.33.4.12
  156.   ______________________________________________________________________
  157.  
  158.   Remember what I said about leading spaces!
  159.  
  160.   The file describes the root name servers in the world.  This changes
  161.   over time and must be maintained.  See the ``maintenance section'' for
  162.   how to keep it up to date.  This file is described in the named man
  163.   page, but it is, IMHO, best suited for people that already understand
  164.   named.
  165.  
  166.   The next line in named.boot is the primary line.  I will explain its
  167.   use in a later chapter, for now just make this a file named 127.0.0 in
  168.   the subdirectory pz:
  169.   ______________________________________________________________________
  170.   @               IN      SOA     ns.linux.bogus. hostmaster.linux.bogus. (
  171.                                   1       ; Serial
  172.                                   28800   ; Refresh
  173.                                   7200    ; Retry
  174.                                   604800  ; Expire
  175.                                   86400)  ; Minimum TTL
  176.                           NS      ns.linux.bogus.
  177.   1                       PTR     localhost.
  178.   ______________________________________________________________________
  179.  
  180.   Next, you need a /etc/resolv.conf looking something like this:
  181.  
  182.   ______________________________________________________________________
  183.   search subdomain.your-domain.edu your-domain.edu
  184.   nameserver 127.0.0.1
  185.   ______________________________________________________________________
  186.  
  187.   The `search' line specifies what domains should be searched for any
  188.   host names you want to connect to.  The `nameserver' line specifies
  189.   the address of your nameserver at, in this case your own machine since
  190.   that is where your named runs.  If you want to list several name
  191.   servers put in one `nameserver' line for each. (Note: Named never
  192.   reads this file, the resolver that uses named does.)
  193.  
  194.   To illustrate what this file does: If a client tries to look up foo,
  195.   foo.subdomain.your-domain.edu is tried first, then foo.your-
  196.   fomain.edu, finally foo.  If a client tries to look up
  197.   sunsite.unc.edu, sunsite.unc.edu.subdomain.your-domain.edu is tried
  198.   first (yes, it's silly, but that's the way it's gotta be) , then
  199.   sunsite.unc.edu.your-domain.edu, and finally sunsite.unc.edu.  You may
  200.   not want to put in too many domains in the search line, it takes time
  201.   to search them.
  202.  
  203.   The example assumes you belong in the domain subdomain.your-
  204.   domain.edu, your machine then, is probably called your-
  205.   machine.subdomain.your-domain.edu.  The search line should not contain
  206.   your TLD (Top Level Domain, `edu' in this case).  If you frequently
  207.   need to connect to hosts in another domain you can add that domain to
  208.   the search line like this:
  209.  
  210.   ______________________________________________________________________
  211.   search subdomain.your-domain.edu your-domain.edu other-domain.com
  212.   ______________________________________________________________________
  213.  
  214.   and so on. Obviously you need to put real domain names in instead.
  215.   Please note the lack of periods at the end of the domain names.
  216.  
  217.   Next, depending on your libc version you either need to fix
  218.   /etc/nsswitch.conf or /etc/host.conf.  If you already have
  219.   nsswitch.conf that's what we'll fix, if not, we'll fix host.conf.
  220.  
  221.   /etc/nsswitch.conf
  222.  
  223.   This is a long file specifying where to get different kinds of data
  224.   types, from what file or database.  It usually contains helpful
  225.   comments at the top, which you should consider reading, now.  After
  226.   that find the line starting with `hosts:', it should read
  227.  
  228.   ______________________________________________________________________
  229.   hosts:      files dns
  230.   ______________________________________________________________________
  231.  
  232.   If there is no line starting with `hosts:' then put in the one above.
  233.   It says that programs should first look in the /etc/hosts file, then
  234.   check DNS according to resolv.conf.
  235.  
  236.   /etc/host.conf
  237.  
  238.   It probably contains several lines, one should starting with order and
  239.   it should look like this:
  240.  
  241.   ______________________________________________________________________
  242.   order hosts,bind
  243.   ______________________________________________________________________
  244.  
  245.   If there is no `order' line you should stick one in.  It tells the
  246.   host name resolving routines to first look in /etc/hosts, then ask the
  247.   name server (which you in resolv.conf said is at 127.0.0.1) These two
  248.   latest files are documented in the resolv(8) man page (do `man 8
  249.   resolv') in most Linux distributions.  That man page is IMHO readable,
  250.   and everyone, especially DNS admins, should read it.  Do it now, if
  251.   you say to yourself "I'll do it later" you'll never get around to it.
  252.  
  253.   3.1.  Starting named
  254.  
  255.   After all this it's time to start named.  If you're using a dialup
  256.   connection connect first.  Type `ndc start', and press return, no
  257.   options.  If that back-fires try `/usr/sbin/ndc start' instead.  If
  258.   that back-fires see the ``FAQ'' section.  Now you can test your setup.
  259.   If you view your syslog message file (usually called
  260.   /var/adm/messages, but another directory to look in is /var/log and
  261.   another file to look in is syslog) while starting named (do tail -f
  262.   /var/adm/messages) you should see something like:
  263.  
  264.        Jun 30 21:50:55 roke named[2258]: starting.  named 4.9.4-REL Sun Jun 30 21:29:03 MET DST 1996   janl@roke.slip.ifi.uio.no:/var/tmp/bind/named
  265.        Jun 30 21:50:55 roke named[2258]: cache zone "" loaded (serial 0)
  266.        Jun 30 21:50:55 roke named[2258]: primary zone "0.0.127.in-addr.arpa" loaded (serial 1)
  267.  
  268.   If there are any messages about errors then there is a mistake.  Named
  269.   will name the file it is in (one of named.boot and root.cache I hope
  270.   :-) Kill named and go back and check the file.
  271.  
  272.   Now it's time to start nslookup to examine your handywork.
  273.  
  274.        $ nslookup
  275.        Default Server:  localhost
  276.        Address:  127.0.0.1
  277.  
  278.        >
  279.  
  280.   If that's what you get it's working.  We hope.  Anything else, go back
  281.   and check everything.  Each time you change the named.boot file you
  282.   need to restart named using the ndc restart command.
  283.  
  284.   Now you can enter a query.  Try looking up some machine close to you.
  285.   pat.uio.no is close to me, at the University of Oslo:
  286.  
  287.        > pat.uio.no
  288.        Server:  localhost
  289.        Address:  127.0.0.1
  290.  
  291.        Name:    pat.uio.no
  292.        Address:  129.240.2.50
  293.  
  294.   nslookup now asked your named to look for the machine pat.uio.no.  It
  295.   then contacted one of the name server machines named in your
  296.   root.cache file, and asked its way from there.  It might take tiny
  297.   while before you get the result as it searches all the domains you
  298.   named in /etc/resolv.conf.
  299.  
  300.   If you try again you get this:
  301.  
  302.        > pat.uio.no
  303.        Server:  localhost
  304.        Address:  127.0.0.1
  305.  
  306.        Non-authoritative answer:
  307.        Name:    pat.uio.no
  308.        Address:  129.240.2.50
  309.  
  310.   Note the `Non-authoritative answer:' line we got this time around.
  311.   That means that named did not go out on the network to ask this time,
  312.   it instead looked in it's cache and found it there.  But the cached
  313.   information might be out of date (stale).  So you are informed of this
  314.   (very slight) danger by it saying `Non-authorative answer:'.  When
  315.   nslookup says this the second time you ask for a host it's a sure sign
  316.   it named caches the information and that it's working.  You exit
  317.   nslookup by giving the command `exit'.
  318.  
  319.   If you're a dialup (ppp, slip) user please read the ``section on
  320.   dialup connections'', there is some advice there for you.
  321.  
  322.   Now you know how to set up a caching named.  Take a beer, milk, or
  323.   whatever you prefer to celebrate it.
  324.  
  325.   4.  A simple domain.
  326.  
  327.   How to set up your own domain.
  328.  
  329.   4.1.  But first some dry theory
  330.  
  331.   Before we really start this section I'm going to serve you some theory
  332.   on how DNS works.  And you're going to read it because it's good for
  333.   you.  If you don't `wanna' you should at least skim it very quickly.
  334.   Stop skimming when you get to what should go in your named.boot file.
  335.  
  336.   DNS is a hierarchical system.  The top is written `.' and pronounced
  337.   `root'.  Under . there are a number of Top Level Domains (TLDs), the
  338.   best known ones are ORG, COM, EDU and NET, but there are many more.
  339.  
  340.   When looking for a machine the query proceeds recursively into the
  341.   hierarchy starting at the top.  If you want to find out the address of
  342.   prep.ai.mit.edu your name server has to find a name server that serves
  343.   edu.  It asks a . server (it already knows the .  servers, that's what
  344.   the root.cache file is for), the .  server gives a list of edu
  345.   servers:
  346.  
  347.        $ nslookup
  348.        Default Server:  localhost
  349.        Address:  127.0.0.1
  350.  
  351.   Start asking a root server.
  352.  
  353.        > server c.root-servers.net.
  354.        Default Server:  c.root-servers.net
  355.        Address:  192.33.4.12
  356.  
  357.   Set the Query type to NS (name server records).
  358.  
  359.        > set q=ns
  360.  
  361.   Ask about edu.
  362.  
  363.        > edu.
  364.  
  365.   The trailing . here is significant, it tells the server we're asking
  366.   that edu is right under . (this narrows the search somewhat).
  367.  
  368.        edu     nameserver = A.ROOT-SERVERS.NET
  369.        edu     nameserver = H.ROOT-SERVERS.NET
  370.        edu     nameserver = B.ROOT-SERVERS.NET
  371.        edu     nameserver = C.ROOT-SERVERS.NET
  372.        edu     nameserver = D.ROOT-SERVERS.NET
  373.        edu     nameserver = E.ROOT-SERVERS.NET
  374.        edu     nameserver = I.ROOT-SERVERS.NET
  375.        edu     nameserver = F.ROOT-SERVERS.NET
  376.        edu     nameserver = G.ROOT-SERVERS.NET
  377.        A.ROOT-SERVERS.NET      internet address = 198.41.0.4
  378.        H.ROOT-SERVERS.NET      internet address = 128.63.2.53
  379.        B.ROOT-SERVERS.NET      internet address = 128.9.0.107
  380.        C.ROOT-SERVERS.NET      internet address = 192.33.4.12
  381.        D.ROOT-SERVERS.NET      internet address = 128.8.10.90
  382.        E.ROOT-SERVERS.NET      internet address = 192.203.230.10
  383.        I.ROOT-SERVERS.NET      internet address = 192.36.148.17
  384.        F.ROOT-SERVERS.NET      internet address = 192.5.5.241
  385.        G.ROOT-SERVERS.NET      internet address = 192.112.36.4
  386.  
  387.   This tells us that *.root-servers.net serves edu., so we can go on
  388.   asking c.  Now we want to know who serves the next level of the domain
  389.   name: mit.edu.:
  390.  
  391.        > mit.edu.
  392.        Server:  c.root-servers.net
  393.        Address:  192.33.4.12
  394.  
  395.        Non-authoritative answer:
  396.        mit.edu nameserver = STRAWB.mit.edu
  397.        mit.edu nameserver = W20NS.mit.edu
  398.        mit.edu nameserver = BITSY.mit.edu
  399.  
  400.        Authoritative answers can be found from:
  401.        STRAWB.mit.edu  internet address = 18.71.0.151
  402.        W20NS.mit.edu   internet address = 18.70.0.160
  403.        BITSY.mit.edu   internet address = 18.72.0.3
  404.  
  405.   steawb, w20ns and bitsy serves mit, select one and inquire about
  406.   ai.mit.edu:
  407.  
  408.   > server W20NS.mit.edu.
  409.  
  410.   Host names are not case sensitive, but I use my mouse to cut and paste
  411.   so it gets copied as-is from the screen.
  412.  
  413.        Server:  W20NS.mit.edu
  414.        Address:  18.70.0.160
  415.  
  416.        > ai.mit.edu.
  417.        Server:  W20NS.mit.edu
  418.        Address:  18.70.0.160
  419.  
  420.        Non-authoritative answer:
  421.        ai.mit.edu      nameserver = WHEATIES.AI.MIT.EDU
  422.        ai.mit.edu      nameserver = ALPHA-BITS.AI.MIT.EDU
  423.        ai.mit.edu      nameserver = GRAPE-NUTS.AI.MIT.EDU
  424.        ai.mit.edu      nameserver = TRIX.AI.MIT.EDU
  425.        ai.mit.edu      nameserver = MUESLI.AI.MIT.EDU
  426.  
  427.        Authoritative answers can be found from:
  428.        AI.MIT.EDU      nameserver = WHEATIES.AI.MIT.EDU
  429.        AI.MIT.EDU      nameserver = ALPHA-BITS.AI.MIT.EDU
  430.        AI.MIT.EDU      nameserver = GRAPE-NUTS.AI.MIT.EDU
  431.        AI.MIT.EDU      nameserver = TRIX.AI.MIT.EDU
  432.        AI.MIT.EDU      nameserver = MUESLI.AI.MIT.EDU
  433.        WHEATIES.AI.MIT.EDU     internet address = 128.52.32.13
  434.        WHEATIES.AI.MIT.EDU     internet address = 128.52.35.13
  435.        ALPHA-BITS.AI.MIT.EDU   internet address = 128.52.32.5
  436.        ALPHA-BITS.AI.MIT.EDU   internet address = 128.52.37.5
  437.        GRAPE-NUTS.AI.MIT.EDU   internet address = 128.52.32.4
  438.        GRAPE-NUTS.AI.MIT.EDU   internet address = 128.52.36.4
  439.        TRIX.AI.MIT.EDU internet address = 128.52.32.6
  440.        TRIX.AI.MIT.EDU internet address = 128.52.38.6
  441.        MUESLI.AI.MIT.EDU       internet address = 128.52.32.7
  442.        MUESLI.AI.MIT.EDU       internet address = 128.52.39.7
  443.  
  444.   So weaties.ai.mit.edu is a nameserver for ai.mit.edu:
  445.  
  446.        > server WHEATIES.AI.MIT.EDU.
  447.        Default Server:  WHEATIES.AI.MIT.EDU
  448.        Addresses:  128.52.32.13, 128.52.35.13
  449.  
  450.   Now I change query type, we've found the name server so now we're
  451.   going to ask about everything wheaties knows about prep.ai.mit.edu.
  452.  
  453.   > set q=any
  454.   > prep.ai.mit.edu.
  455.   Server:  WHEATIES.AI.MIT.EDU
  456.   Addresses:  128.52.32.13, 128.52.35.13
  457.  
  458.   prep.ai.mit.edu CPU = dec/decstation-5000.25    OS = unix
  459.   prep.ai.mit.edu
  460.           inet address = 18.159.0.42, protocol = tcp
  461.            #21 #23 #25 #79
  462.   prep.ai.mit.edu preference = 1, mail exchanger = life.ai.mit.edu
  463.   prep.ai.mit.edu internet address = 18.159.0.42
  464.   ai.mit.edu      nameserver = alpha-bits.ai.mit.edu
  465.   ai.mit.edu      nameserver = wheaties.ai.mit.edu
  466.   ai.mit.edu      nameserver = grape-nuts.ai.mit.edu
  467.   ai.mit.edu      nameserver = mini-wheats.ai.mit.edu
  468.   ai.mit.edu      nameserver = trix.ai.mit.edu
  469.   ai.mit.edu      nameserver = muesli.ai.mit.edu
  470.   ai.mit.edu      nameserver = count-chocula.ai.mit.edu
  471.   ai.mit.edu      nameserver = life.ai.mit.edu
  472.   ai.mit.edu      nameserver = mintaka.lcs.mit.edu
  473.   life.ai.mit.edu internet address = 128.52.32.80
  474.   alpha-bits.ai.mit.edu   internet address = 128.52.32.5
  475.   wheaties.ai.mit.edu     internet address = 128.52.35.13
  476.   wheaties.ai.mit.edu     internet address = 128.52.32.13
  477.   grape-nuts.ai.mit.edu   internet address = 128.52.36.4
  478.   grape-nuts.ai.mit.edu   internet address = 128.52.32.4
  479.   mini-wheats.ai.mit.edu  internet address = 128.52.32.11
  480.   mini-wheats.ai.mit.edu  internet address = 128.52.54.11
  481.   mintaka.lcs.mit.edu     internet address = 18.26.0.36
  482.  
  483.   So starting at . we found the successive name servers for the next
  484.   level in the domain name.  If you had used your own DNS server instead
  485.   of using all those other servers, your named would of-course cache all
  486.   the information it found while digging this out for you, and it would
  487.   not have to ask again for a while.
  488.  
  489.   A much less talked about, but just as important domain is in-
  490.   addr.arpa.  It too is nested like the `normal' domains.  in-addr.arpa
  491.   allows us to get the hosts name when we have it's address.  A
  492.   important thing here is to note that ip#s are written in reverse order
  493.   in the in-addr.arpa domain.  If you have the address of a machine:
  494.   192.128.52.43 named proceeds just like for the prep.ai.mit.edu
  495.   example: find arpa. servers.  Find in-addr.arpa. servers, find 192.in-
  496.   addr.arpa. servers, find 128.192.in-addr.arpa. servers, find
  497.   52.128.192.in-addr.arpa.  servers.  Find needed records for
  498.   43.52.128.192.in-addr.arpa.  Clever huh? (Say `yes'.)  The reversion
  499.   of the numbers can be confusing the first 2 years.
  500.  
  501.   I have just told a lie.  DNS does not work literally the way I just
  502.   told you.  But it's close enough.
  503.  
  504.   4.2.  Our own domain
  505.  
  506.   Now to define our own domain.  We're going to make the domain
  507.   linux.bogus and define machines in it.  I use a totally bogus domain
  508.   name to make sure we disturb no-one Out There.
  509.  
  510.   We've already started this part with this line in named.boot:
  511.  
  512.   ______________________________________________________________________
  513.   primary         0.0.127.in-addr.arpa            pz/127.0.0
  514.   ______________________________________________________________________
  515.  
  516.   Please note the lack of `.' at the end of the domain names in this
  517.   file.  The first line names the file pz/127.0.0 as defining
  518.   0.0.127.in-addr.arpa.  We've already set up this file, it reads:
  519.  
  520.   ______________________________________________________________________
  521.   @               IN      SOA     ns.linux.bogus. hostmaster.linux.bogus. (
  522.                                   1       ; Serial
  523.                                   28800   ; Refresh
  524.                                   7200    ; Retry
  525.                                   604800  ; Expire
  526.                                   86400)  ; Minimum TTL
  527.                           NS      ns.linux.bogus.
  528.   1                       PTR     localhost.
  529.   ______________________________________________________________________
  530.  
  531.   Please note the `.' at the end of all the full domain names in this
  532.   file, in contrast to the named.boot file above.  Some people like to
  533.   start each zone file with a $ORIGIN directive, but this is
  534.   superfluous.  The origin (where in the DNS hierarchy it belongs) of a
  535.   zone file is specified in the `domain' column of the named.boot file,
  536.   in this case it's 0.0.127.in-addr.arpa.
  537.  
  538.   This `zone file' contains 3 `resource records' (RRs): A SOA RR.  A NS
  539.   RR and a PTR RR.  SOA is short for Start Of Authority.  The `@' is a
  540.   special notation meaning the origin, and since the `domain' column for
  541.   this file says 0.0.127.in-addr.arpa the first line really means
  542.  
  543.          0.0.127.IN-ADDR.ARPA. IN      SOA ...
  544.  
  545.   NS is the Name Server RR, it tells DNS what machine is the name server
  546.   of the domain.  And finally the PTR record says that 1 (equals
  547.   1.0.0.127.IN-ADDR.ARPA, i.e. 127.0.0.1) is named localhost.
  548.  
  549.   The SOA record is the preamble to all zone files, and there should be
  550.   exactly one in each zone file, the very first record.  It describes
  551.   the zone, where it comes from (a machine called linux.bogus), who is
  552.   responsible for its contents (hostmaster@linux.bogus), what version of
  553.   the zone file this is (serial: 1), and other things having to do with
  554.   caching and secondary DNS servers.  For the rest of the fields
  555.   ,refresh, retry, expire and minimum use the numbers used in this HOWTO
  556.   and you should be safe.
  557.  
  558.   The NS record tells us who does DNS serving for 0.0.127.in-addr.arpa,
  559.   it is ns.linux.bogus.  The PTR record tells us that 1.0.0.127.in-
  560.   addr.arpa (aka 127.0.0.1) is known as localhost.
  561.  
  562.   Now restart your named (the command is ndc restart) and use nslookup
  563.   to examine what you've done:
  564.  
  565.        $ nslookup
  566.  
  567.        Default Server:  localhost
  568.        Address:  127.0.0.1
  569.  
  570.        > 127.0.0.1
  571.        Server:  localhost
  572.        Address:  127.0.0.1
  573.  
  574.        Name:    localhost
  575.        Address:  127.0.0.1
  576.  
  577.   so it manages to get localhost from 127.0.0.1, good.  Now for our main
  578.   task, the linux.bogus domain, insert a new primary line in named.boot:
  579.  
  580.   ______________________________________________________________________
  581.   primary               linux.bogus                     pz/linux.bogus
  582.   ______________________________________________________________________
  583.  
  584.   Note the continued lack of ending `.' on the domain name in the
  585.   named.boot file.
  586.  
  587.   In the linux.bogus zone file we'll put some totally bogus data:
  588.  
  589.   ______________________________________________________________________
  590.   ;
  591.   ; Zone file for linux.bogus
  592.   ;
  593.   ; Mandatory minimum for a working domain
  594.   ;
  595.   @       IN      SOA     ns.linux.bogus. hostmaster.linux.bogus. (
  596.                           199511301       ; serial, todays date + todays serial #
  597.                           28800           ; refresh, seconds
  598.                           7200            ; retry, seconds
  599.                           3600000         ; expire, seconds
  600.                           86400 )         ; minimum, seconds
  601.                   NS      ns.linux.bogus.
  602.                   NS      ns.friend.bogus.
  603.                   MX      10 mail.linux.bogus   ; Primary Mail Exchanger
  604.                   MX      20 mail.friend.bogus. ; Secondary Mail Exchanger
  605.  
  606.   localhost       A       127.0.0.1
  607.   ns              A       127.0.0.2
  608.   mail            A       127.0.0.4
  609.   ______________________________________________________________________
  610.  
  611.   Two things must be noted about the SOA record.  ns.linux.bogus must be
  612.   a actual machine with a A record.  It is not legal to have a CNAME
  613.   record for he machine mentioned in the SOA record.  It's name need not
  614.   be `ns', it could be any legal host name. Next, hostmaster.linux.bogus
  615.   should be read as hostmaster@linux.bogus, this should be a mail alias,
  616.   or a mailbox, where the person(s) maintaining DNS should read mail
  617.   frequently.  Any mail regarding the domain will be sent to the address
  618.   listed here.  The name need not be `hostmaster', it can be any legal
  619.   e-mail address, but the e-mail address `hostmaster' is expected to
  620.   work as well.
  621.  
  622.   There is one new RR type in this file, the MX, or Mail eXchanger RR.
  623.   It tells mail systems where to send mail that is addressed to
  624.   someone@linux.bogus, namely too mail.linux.bogus or mail.friend.bogus.
  625.   The number before each machine name is that MX RRs priority.  The RR
  626.   with the lowest number (10) is the one mail should be sent to
  627.   primarily.  If that fails it can be sent to one with a higher number,
  628.   a secondary mail handler, i.e. mail.friend.bogus which has priority 20
  629.   here.
  630.  
  631.   Restart named by running ndc restart.  Examine the results with
  632.   nslookup:
  633.  
  634.        $ nslookup
  635.        > set q=any
  636.        > linux.bogus
  637.        Server:  localhost
  638.        Address:  127.0.0.1
  639.  
  640.        linux.bogus
  641.                origin = linux.bogus
  642.                mail addr = hostmaster.linux.bogus
  643.                serial = 199511301
  644.                refresh = 28800 (8 hours)
  645.                retry   = 7200 (2 hours)
  646.                expire  = 604800 (7 days)
  647.                minimum ttl = 86400 (1 day)
  648.        linux.bogus     nameserver = ns.linux.bogus
  649.        linux.bogus     nameserver = ns.friend.bogus
  650.        linux.bogus     preference = 10, mail exchanger = mail.linux.bogus.linux.bogus
  651.        linux.bogus     preference = 20, mail exchanger = mail.friend.bogus
  652.        linux.bogus     nameserver = ns.linux.bogus
  653.        linux.bogus     nameserver = ns.friend.bogus
  654.        ns.linux.bogus  internet address = 127.0.0.2
  655.        mail.linux.bogus        internet address = 127.0.0.4
  656.  
  657.   Upon careful examination you will discover a bug.  The line
  658.  
  659.          linux.bogus     preference = 10, mail exchanger = mail.linux.bogus.linux.bogus
  660.  
  661.   is all wrong.  It should be
  662.  
  663.          linux.bogus     preference = 10, mail exchanger = mail.linux.bogus
  664.  
  665.   I deliberately made a mistake so you could learn from it :-) Looking
  666.   in the zone file we find that the line
  667.  
  668.        @               MX      10 mail.linux.bogus     ; Primary Mail Exchanger
  669.  
  670.   is missing a period.  Or has a 'linux.bogus' too many.  If a machine
  671.   name does not end in a period in a zone file the origin is added to
  672.   it's end.  So either
  673.  
  674.   ______________________________________________________________________
  675.   @               MX      10 mail.linux.bogus.    ; Primary Mail Exchanger
  676.   ______________________________________________________________________
  677.  
  678.   or
  679.  
  680.   ______________________________________________________________________
  681.   @               MX      10 mail                 ; Primary Mail Exchanger
  682.   ______________________________________________________________________
  683.  
  684.   is correct.  I prefer the latter form, it's less to type.  In a zone
  685.   file the domain should either be written out and ended with a `.'  or
  686.   it should not be included at all, in which case it defaults to the
  687.   origin.  I must stress that in the named.boot file there should not be
  688.   `.'s after the domain names.  You have no idea how many times a `.'
  689.   too many or few have fouled up things and confused the h*ll out of
  690.   people.
  691.  
  692.   So having made my point here is the new zone file, with some extra
  693.   information in it as well:
  694.  
  695.   ______________________________________________________________________
  696.   ;
  697.   ; Zone file for linux.bogus
  698.   ;
  699.   ; Mandatory minimum for a working domain
  700.   ;
  701.   @       IN      SOA     ns.linux.bogus. hostmaster.linux.bogus. (
  702.                           199511301       ; serial, todays date + todays serial #
  703.                           28800           ; refresh, seconds
  704.                           7200            ; retry, seconds
  705.                           604800          ; expire, seconds
  706.                           86400 )         ; minimum, seconds
  707.  
  708.                   NS      ns              ; Inet Address of name server
  709.                   NS      ns.friend.bogus.
  710.                   MX      10 mail         ; Primary Mail Exchanger
  711.                   MX      20 mail.friend.bogus. ; Secondary Mail Exchanger
  712.  
  713.   localhost       A       127.0.0.1
  714.   ns              A       127.0.0.2
  715.   mail            A       127.0.0.4
  716.   ;
  717.   ; Extras
  718.   ;
  719.   @               TXT     "Linux.Bogus, your DNS consultants"
  720.  
  721.   ns              MX      10 mail
  722.                   MX      20 mail.friend.bogus.
  723.                   HINFO   "Pentium" "Linux 1.2"
  724.                   TXT     "RMS"
  725.   richard         CNAME   ns
  726.   www             CNAME   ns
  727.  
  728.   donald          A       127.0.0.3
  729.                   MX      10 mail
  730.                   MX      20 mail.friend.bogus.
  731.                   HINFO   "i486"  "Linux 1.2"
  732.                   TXT     "DEK"
  733.  
  734.   mail            MX      10 mail
  735.                   MX      20 mail.friend.bogus.
  736.                   HINFO   "386sx" "Linux 1.0.9"
  737.  
  738.   ftp             A       127.0.0.5
  739.                   MX      10 mail
  740.                   MX      20 mail.friend.bogus.
  741.                   HINFO   "P6" "Linux 1.3.59"
  742.   ______________________________________________________________________
  743.  
  744.   You might want to move the first three A records so that they're
  745.   placed next to their respective other records, instead on top like
  746.   that.
  747.  
  748.   There are a number of new RRs here: HINFO (Host INFOrmation) has two
  749.   parts, it's a good habit to quote each.  The first part is the
  750.   hardware or CPU on the machine, and the second part the software or OS
  751.   on the machine.  ns has a Pentium CPU and runs Linux 1.2.  The TXT
  752.   record is a free text record that you can use for anything you like.
  753.   CNAME (Canonical NAME) is a way to give each machine several names.
  754.   So richard and www is a alias for ns.  It's important to note that A
  755.   MX, CNAME and SOA record should never refer to a CNAME record, they
  756.   should only refer to something with a A record, so it would wrong to
  757.   have
  758.  
  759.   ______________________________________________________________________
  760.   foobar  CNAME   richard                 ; NO!
  761.   ______________________________________________________________________
  762.  
  763.   but correct to have
  764.  
  765.   ______________________________________________________________________
  766.   foobar  CNAME   ns                      ; Yes!
  767.   ______________________________________________________________________
  768.  
  769.   It's also important to note that a CNAME is not a legal host name for
  770.   a e-mail address: webmaster@www.linux.bogus is an illegal e-mail
  771.   address given the setup above.  You can expect quite a few mail admins
  772.   Out There to enforce this rule even if it works for you.  The way to
  773.   avoid this is to use A records (and perhaps some others too, like a MX
  774.   record) instead:
  775.  
  776.   ______________________________________________________________________
  777.   www     A       127.0.0.2
  778.   ______________________________________________________________________
  779.  
  780.   Paul Vixie, the primary named wizard, recommends not using CNAME.  So
  781.   consider not using it very seriously.
  782.  
  783.   Load the new database by running ndc reload, this causes named to read
  784.   its files again.
  785.  
  786.        $ nslookup
  787.        Default Server:  localhost
  788.        Address:  127.0.0.1
  789.  
  790.        > ls -d linux.bogus
  791.  
  792.   This means that all records should be listed.
  793.  
  794.   [localhost]
  795.    linux.bogus.                   SOA   ns.linux.bogus hostmaster.linux.bogus. (199511301 28800 7200 604800 86400)
  796.    linux.bogus.                   NS    ns.linux.bogus
  797.    linux.bogus.                   NS    ns.friend.bogus
  798.    linux.bogus.                   MX    10   mail.linux.bogus
  799.    linux.bogus.                   MX    20   mail.friend.bogus
  800.    linux.bogus.                   TXT   "Linux.Bogus, your DNS consultants"
  801.    localhost                      A     127.0.0.1
  802.    mail                           A     127.0.0.4
  803.    mail                           MX    10   mail.linux.bogus
  804.    mail                           MX    20   mail.friend.bogus
  805.    mail                           HINFO 386sx       Linux 1.0.9
  806.    donald                         A     127.0.0.3
  807.    donald                         MX    10   mail.linux.bogus
  808.    donald                         MX    20   mail.friend.bogus
  809.    donald                         HINFO i486        Linux 1.2
  810.    donald                         TXT   "DEK"
  811.    www                            CNAME ns.linux.bogus
  812.    richard                        CNAME ns.linux.bogus
  813.    ftp                            A     127.0.0.5
  814.    ftp                            MX    10   mail.linux.bogus
  815.    ftp                            MX    20   mail.friend.bogus
  816.    ftp                            HINFO P6          Linux 1.3.59
  817.    ns                             A     127.0.0.2
  818.    ns                             MX    10   mail.linux.bogus
  819.    ns                             MX    20   mail.friend.bogus
  820.    ns                             HINFO Pentium     Linux 1.2
  821.    ns                             TXT   "RMS"
  822.    linux.bogus.                   SOA   ns.linux.bogus hostmaster.linux.bogus. (199511301 28800 7200 604800 86400)
  823.  
  824.   That's good.  Let's check what it says for www alone:
  825.  
  826.        > set q=any
  827.        > www.linux.bogus.
  828.        Server:  localhost
  829.        Address:  127.0.0.1
  830.  
  831.        www.linux.bogus canonical name = ns.linux.bogus
  832.  
  833.   ns.linux.bogus
  834.  
  835.        linux.bogus     nameserver = ns.linux.bogus
  836.        linux.bogus     nameserver = ns.friend.bogus
  837.        ns.linux.bogus  internet address = 127.0.0.2
  838.  
  839.   and ns.linux.bogus has the address 127.0.0.2.  Looks good too.
  840.  
  841.   4.3.  Winding down
  842.  
  843.   Of course, this domain is highly bogus, and so are all the addresses
  844.   in it, and it is perhaps, unfortunately a bit confusing.  For a real
  845.   example of a real domain see the next section.
  846.  
  847.   5.  A real domain example
  848.  
  849.   Where we list some real zone files
  850.  
  851.   Users have suggested that I include a real example of a working domain
  852.   as my explanation of what the differences between a working domain and
  853.   the bogus example was was a bit unclear.
  854.  
  855.   One thing about this example: Do not enter it into your name servers!
  856.   Use it only to read for reference.  If you want to experiment do that
  857.   with the bogus example.  I use this example with permission from David
  858.   Bullock of LAND-5.  These files were current 24th of September 1996,
  859.   and might differ from what you find if you query LAND-5's name servers
  860.   now.  Also, keep in mind: delete the leading spaces ;-)
  861.  
  862.   5.1.  /etc/named.boot (or /var/named/named.boot)
  863.  
  864.   Here we find primary lines for the two reverse zones needed: the
  865.   127.0.0 net, as well as LAND-5's 206.6.177 subnet.  And a primary line
  866.   for land-5's forward zone land-5.com.  Also note that instead of
  867.   stuffing the files in a directory called pz, as I do in this HOWTO, he
  868.   puts them in a directory called zone.
  869.  
  870.   ______________________________________________________________________
  871.   ;  Boot file for LAND-5 name server
  872.   ;
  873.   directory /var/named
  874.   ;
  875.   ; type          domain                          source file or host
  876.   cache           .                               root.cache
  877.   primary         0.0.127.in-addr.arpa            zone/127.0.0
  878.   primary         177.6.206.in-addr.arpa          zone/206.6.177
  879.   primary         land-5.com                      zone/land-5.com
  880.   ______________________________________________________________________
  881.  
  882.   5.2.  /var/named/root.cache
  883.  
  884.   Keep in mind that this file is dynamic, and the one listed here is
  885.   old.  You're better off using one produced now, with dig.
  886.  
  887.   ______________________________________________________________________
  888.   ; <<>> DiG 2.1 <<>>
  889.   ;; res options: init recurs defnam dnsrch
  890.   ;; got answer:
  891.   ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 6
  892.   ;; flags: qr rd ra; Ques: 1, Ans: 9, Auth: 0, Addit: 9
  893.   ;; QUESTIONS:
  894.   ;;      ., type = NS, class = IN
  895.  
  896.   ;; ANSWERS:
  897.    .       518357  NS      H.ROOT-SERVERS.NET.
  898.    .       518357  NS      B.ROOT-SERVERS.NET.
  899.    .       518357  NS      C.ROOT-SERVERS.NET.
  900.    .       518357  NS      D.ROOT-SERVERS.NET.
  901.    .       518357  NS      E.ROOT-SERVERS.NET.
  902.    .       518357  NS      I.ROOT-SERVERS.NET.
  903.    .       518357  NS      F.ROOT-SERVERS.NET.
  904.    .       518357  NS      G.ROOT-SERVERS.NET.
  905.    .       518357  NS      A.ROOT-SERVERS.NET.
  906.  
  907.   ;; ADDITIONAL RECORDS:
  908.   H.ROOT-SERVERS.NET.     165593  A       128.63.2.53
  909.   B.ROOT-SERVERS.NET.     165593  A       128.9.0.107
  910.   C.ROOT-SERVERS.NET.     222766  A       192.33.4.12
  911.   D.ROOT-SERVERS.NET.     165593  A       128.8.10.90
  912.   E.ROOT-SERVERS.NET.     165593  A       192.203.230.10
  913.   I.ROOT-SERVERS.NET.     165593  A       192.36.148.17
  914.   F.ROOT-SERVERS.NET.     299616  A       192.5.5.241
  915.   G.ROOT-SERVERS.NET.     165593  A       192.112.36.4
  916.   A.ROOT-SERVERS.NET.     165593  A       198.41.0.4
  917.  
  918.   ;; Total query time: 250 msec
  919.   ;; FROM: land-5 to SERVER: default -- 127.0.0.1
  920.   ;; WHEN: Fri Sep 20 10:11:22 1996
  921.   ;; MSG SIZE  sent: 17  rcvd: 312
  922.   ______________________________________________________________________
  923.  
  924.   5.3.  /var/named/zone/127.0.0
  925.  
  926.   Just the basics, the obligatory SOA record, and a record that maps
  927.   127.0.0.1 to localhost.  Both are required.  No more should be in this
  928.   file.  It will probably never need to be updated, unless your
  929.   nameserver or hostmaster address changes.
  930.  
  931.   ______________________________________________________________________
  932.   @               IN      SOA     land-5.com. root.land-5.com. (
  933.                                   199609203       ; Serial
  934.                                   28800   ; Refresh
  935.                                   7200    ; Retry
  936.                                   604800  ; Expire
  937.                                   86400)  ; Minimum TTL
  938.                           NS      land-5.com.
  939.  
  940.   1                       PTR     localhost.
  941.   ______________________________________________________________________
  942.  
  943.   5.4.  /var/named/zone/land-5.com
  944.  
  945.   Here we see the mandatory SOA record, the needed NS records.  We can
  946.   see that he has a secondary name server at ns2.psi.net.  This is as it
  947.   should be, always have a off site secondary server as backup.  We can
  948.   also see that he as a master host called land-5 which takes care of
  949.   all the different services, and that he's done it with CNAMEs (a
  950.   alternative is using A records).
  951.  
  952.   As you see from the SOA record, the zone file originates at
  953.   land-5.com, the contact person is root@land-5.com. hostmaster is
  954.   another oft used address for the contact person.  The serial number is
  955.   in the customary yyyymmdd format with todays serial number appended;
  956.   this is probably the sixth version of zone file on the 20th of
  957.   September 1996.  Remember that the serial number must increase
  958.   monotonically, here there is only one digit for todays serial#, so
  959.   after 9 edits he has to wait until tomorrow before he can edit the
  960.   file again.  Consider using two digits.
  961.  
  962.   ______________________________________________________________________
  963.   @       IN      SOA     land-5.com. root.land-5.com. (
  964.                           199609206       ; serial, todays date + todays serial #
  965.                           10800           ; refresh, seconds
  966.                           7200            ; retry, seconds
  967.                           10800           ; expire, seconds
  968.                           86400 )         ; minimum, seconds
  969.                   NS      land-5.com.
  970.                   NS      ns2.psi.net.
  971.                   MX      10 land-5.com.  ; Primary Mail Exchanger
  972.  
  973.   localhost       A       127.0.0.1
  974.  
  975.   router          A       206.6.177.1
  976.  
  977.   land-5.com.     A       206.6.177.2
  978.   ns              CNAME   land-5.com.
  979.   ftp             CNAME   land-5.com.
  980.   www             CNAME   land-5.com.
  981.   mail            CNAME   land-5.com.
  982.   news            CNAME   land-5.com.
  983.  
  984.   funn            A       206.6.177.3
  985.   illusions       CNAME   funn.land-5.com.
  986.   @               TXT     "LAND-5 Corporation"
  987.  
  988.   ;
  989.   ;       Workstations
  990.   ;
  991.   ws_177200       A       206.6.177.200
  992.                   MX      10 land-5.com.   ; Primary Mail Host
  993.   ws_177201       A       206.6.177.201
  994.                   MX      10 land-5.com.   ; Primary Mail Host
  995.   ws_177202       A       206.6.177.202
  996.                   MX      10 land-5.com.   ; Primary Mail Host
  997.   ws_177203       A       206.6.177.203
  998.                   MX      10 land-5.com.   ; Primary Mail Host
  999.   ws_177204       A       206.6.177.204
  1000.                   MX      10 land-5.com.   ; Primary Mail Host
  1001.   ws_177205       A       206.6.177.205
  1002.                   MX      10 land-5.com.   ; Primary Mail Host
  1003.   ; {Many repetitive definitions deleted - SNIP}
  1004.   ws_177250       A       206.6.177.250
  1005.                   MX      10 land-5.com.   ; Primary Mail Host
  1006.   ws_177251       A       206.6.177.251
  1007.                   MX      10 land-5.com.   ; Primary Mail Host
  1008.   ws_177252       A       206.6.177.252
  1009.                   MX      10 land-5.com.   ; Primary Mail Host
  1010.   ws_177253       A       206.6.177.253
  1011.                   MX      10 land-5.com.   ; Primary Mail Host
  1012.   ws_177254       A       206.6.177.254
  1013.                   MX      10 land-5.com.   ; Primary Mail Host
  1014.   ______________________________________________________________________
  1015.  
  1016.   Another thing to note is that the workstations don't have individual
  1017.   names, but rather a prefix followed by the two last parts of the IP
  1018.   numbers.  Using such a convention can simplify maintenance
  1019.   significantly, but can be a bit impersonal.
  1020.  
  1021.   5.5.  /var/named/zone/206.6.177
  1022.  
  1023.   I'll comment on this file after it.
  1024.  
  1025.   ______________________________________________________________________
  1026.   @               IN      SOA     land-5.com. root.land-5.com. (
  1027.                                   199609206       ; Serial
  1028.                                   28800   ; Refresh
  1029.                                   7200    ; Retry
  1030.                                   604800  ; Expire
  1031.                                   86400)  ; Minimum TTL
  1032.                           NS      land-5.com.
  1033.                           NS      ns2.psi.net.
  1034.   ;
  1035.   ;       Servers
  1036.   ;
  1037.   1       PTR     router.land-5.com.
  1038.   2       PTR     land-5.com.
  1039.   3       PTR     funn.land-5.com.
  1040.   ;
  1041.   ;       Workstations
  1042.   ;
  1043.   200     PTR     ws_177200.land-5.com.
  1044.   201     PTR     ws_177201.land-5.com.
  1045.   202     PTR     ws_177202.land-5.com.
  1046.   203     PTR     ws_177203.land-5.com.
  1047.   204     PTR     ws_177204.land-5.com.
  1048.   205     PTR     ws_177205.land-5.com.
  1049.   ; {Many repetitive definitions deleted - SNIP}
  1050.   250     PTR     ws_177250.land-5.com.
  1051.   251     PTR     ws_177251.land-5.com.
  1052.   252     PTR     ws_177252.land-5.com.
  1053.   253     PTR     ws_177253.land-5.com.
  1054.   254     PTR     ws_177254.land-5.com.
  1055.   ______________________________________________________________________
  1056.  
  1057.   The reverse zone is the bit of the setup that seems to cause the most
  1058.   grief.  It is used to find the host name if you have the IP number of
  1059.   a machine.  Example: you are an irc server and accept connections from
  1060.   irc clients.  However you are a Norwegian irc server and so you only
  1061.   want to accept connections from clients in Norway and other
  1062.   Scandinavian countries.  When you get a connection from a client the C
  1063.   library is able to tell you the IP number of the connecting machine
  1064.   because the IP number of the client is contained in all the packets
  1065.   that are passed over the network.  Now you can call a function called
  1066.   gethostbyaddr that looks up the name of a host given the IP number.
  1067.   Gethostbyaddr will ask a DNS server, which will then traverse the DNS
  1068.   looking for the machine.  Supposing the client connection is from
  1069.   ws_177200.land-5.com.  The IP number the C library provides to the irc
  1070.   server is 206.6.177.200.  To find out the name of that machine we need
  1071.   to find 200.177.6.206.in-addr.arpa.  The DNS server will first find
  1072.   the arpa. servers, then find in-addr.arpa. servers, following the
  1073.   reverse trail through 206, then 6 and at last finding the server for
  1074.   the 177.6.206.in-addr.arpa zone at land-5.  From which it will finally
  1075.   get the answer that for 200.177.6.206.in-addr.arpa we have a 'PTR
  1076.   ws_177200.land-5.com' record, meaning that the name that goes with
  1077.   206.6.177.200 is ws_177200.land-5.com.  As with the explanation of how
  1078.   prep.ai.mit.edu is looked up, this is slightly fictitious.
  1079.  
  1080.   Getting back to the irc server example.  The irc server only accepts
  1081.   connections from the Scandinavian countries, i.e., *.no, *.se, *.dk,
  1082.   the name ws_177200.land-5.com clearly does not match any of those, and
  1083.   the server will deny the connection.  If there was no reverse mapping
  1084.   of 206.2.177.200 through the in-addr.arpa zone the server would have
  1085.   been unable to find the name at all and would have to settle to
  1086.   comparing 206.2.177.200 with *.no, *.se and *.dk, none of which will
  1087.   match.
  1088.  
  1089.   Some people will tell you that reverse lookup mappings are only
  1090.   important for servers, or not important at all.  Not so: Many ftp,
  1091.   news, irc and even some http (WWW) servers will not accept connections
  1092.   from machines that they are not able to find the name of.  So reverse
  1093.   mappings for machines are in fact mandatory.
  1094.  
  1095.   6.  Maintenance
  1096.  
  1097.   Keeping it working.
  1098.  
  1099.   There is one maintenance task you have to do on nameds, other than
  1100.   keeping them running.  That's keeping the root.cache file updated.
  1101.   The easiest way is using dig, first run dig with no arguments, you
  1102.   will get the root.cache according to your own server.  Then ask one of
  1103.   the listed root servers with dig @rootserver . ns.  You will note that
  1104.   the output looks terribly like a root.cache file except for a couple
  1105.   of extra numbers.  Those numbers are harmless.  Save it to a file (dig
  1106.   @e.root-servers.net . ns >root.cache.new) and replace the old
  1107.   root.cache with it.
  1108.  
  1109.   Remember to restart named after replacing the cache file.
  1110.  
  1111.   Al Longyear sent me this script that can be run automatically to
  1112.   update root.cache, install a crontab entry to run it once a month and
  1113.   forget it.  The script assumes you have mail working and that the
  1114.   mail-alias `hostmaster' is defined.  You must hack it to suit your
  1115.   setup.
  1116.  
  1117.   ______________________________________________________________________
  1118.   #!/bin/sh
  1119.   #
  1120.   # Update the nameserver cache information file once per month.
  1121.   # This is run automatically by a cron entry.
  1122.   #
  1123.   (
  1124.    echo "To: hostmaster <hostmaster>"
  1125.    echo "From: system <root>"
  1126.    echo "Subject: Automatic update of the named.boot file"
  1127.    echo
  1128.  
  1129.    export PATH=/sbin:/usr/sbin:/bin:/usr/bin:
  1130.    cd /var/named
  1131.  
  1132.    dig @rs.internic.net . ns >root.cache.new
  1133.  
  1134.    echo "The named.boot file has been updated to contain the following
  1135.   information:"
  1136.    echo
  1137.    cat root.cache.new
  1138.  
  1139.    chown root.root root.cache.new
  1140.    chmod 444 root.cache.new
  1141.    rm -f root.cache.old
  1142.    mv root.cache root.cache.old
  1143.    mv root.cache.new root.cache
  1144.    ndc restart
  1145.    echo
  1146.    echo "The nameserver has been restarted to ensure that the update is complete."
  1147.    echo "The previous root.cache file is now called
  1148.   /var/named/root.cache.old."
  1149.   ) 2>&1 | /usr/lib/sendmail -t
  1150.   exit 0
  1151.   ______________________________________________________________________
  1152.  
  1153.   Some of you might have picked up that the root.cache file is also
  1154.   available by ftp from Internic.  Please don't use ftp to update
  1155.   root.cache, the above method is much more friendly to the net.
  1156.  
  1157.   7.  Automatic setup for dialup connections.
  1158.  
  1159.   This section explains how I have set things up to automate everything.
  1160.   My way might not suit you at all, but you might get a idea from
  1161.   something I've done.  Also, I use ppp for dialup, while many use slip
  1162.   or cslip, so almost everything in your setup can be different from
  1163.   mine.  But slip's dip program should be able to do many of the things
  1164.   I do.
  1165.  
  1166.   Normally, when I'm not connected to the net I have a resolv.conf file
  1167.   simply containing the line
  1168.  
  1169.        domain uio.no
  1170.  
  1171.   This ensures I don't have to wait for the host name resolving library
  1172.   to try to connect to a nameserver that can't help me.  But when I
  1173.   connect I want to start my named and have a resolv.conf looking like
  1174.   the one described above.  I have solved this by keeping two
  1175.   resolv.conf 'template' files named resolv.conf.local and
  1176.   resolv.conf.connected.  The latter looks like the resolv.conf
  1177.   described before in this document.
  1178.  
  1179.   To automatically connect to the net I run a script called 'ppp-on':
  1180.  
  1181.   ______________________________________________________________________
  1182.   #!/bin/sh
  1183.   echo calling...
  1184.   pppd
  1185.   ______________________________________________________________________
  1186.  
  1187.   pppd has a file called options that tells it the particulars of how to
  1188.   get connected.  Once my ppp connection is up the pppd starts a script
  1189.   called ip-up (this is described in the pppd man page).  This is parts
  1190.   of the script:
  1191.  
  1192.   ______________________________________________________________________
  1193.   #!/bin/sh
  1194.   interface="$1"
  1195.   device="$2"
  1196.   speed="$3"
  1197.   myip="$4"
  1198.   upip="$5"
  1199.    ...
  1200.   cp -v /etc/resolv.conf.connected /etc/resolv.conf
  1201.    ...
  1202.   /usr/sbin/named
  1203.   ______________________________________________________________________
  1204.  
  1205.   I.e. I start my named there.  When ppp is disconnected pppd runs a
  1206.   script called ip-down:
  1207.  
  1208.   ______________________________________________________________________
  1209.   #!/bin/sh
  1210.   cp /etc/resolv.conf.local /etc/resolv.conf
  1211.   read namedpid </var/run/named.pid
  1212.   kill $namedpid
  1213.   ______________________________________________________________________
  1214.  
  1215.   So this gets things configured and up when connecting and Dis-
  1216.   configured and down when disconnecting.
  1217.  
  1218.   Some programs, irc and talk come to mind, make a few too many
  1219.   assumptions, and for irc the dcc features and talk to work right you
  1220.   have to fix your hosts file.  I insert have this in my ip-up script:
  1221.  
  1222.   ______________________________________________________________________
  1223.   cp /etc/hosts.ppp /etc/hosts
  1224.   echo $myip      roke >>/etc/hosts
  1225.   ______________________________________________________________________
  1226.  
  1227.   hosts.ppp simply contains
  1228.  
  1229.   ______________________________________________________________________
  1230.   127.0.0.1       localhost
  1231.   ______________________________________________________________________
  1232.  
  1233.   and the echo thing inserts the ip# i have received for my host name
  1234.   (roke).  You should use the name your host knows itself by instead.
  1235.   This can be found with the hostname command.
  1236.  
  1237.   It is probably not smart to run named when you are not connected to
  1238.   the net, this is because named will try to send queries to the net and
  1239.   it has a long timeout, and you have to wait for this timeout every
  1240.   time some program tries to resolve a name.  If you're using dialup you
  1241.   should start named when connecting and kill it when disconnecting.
  1242.   But please see the ``FAQ'' section for a tip.
  1243.  
  1244.   Some people like to use a forwarders directive on slow connections.
  1245.   If your internet provider has DNS servers at 1.2.3.4 and 1.2.3.5 you
  1246.   can insert the line
  1247.  
  1248.   ______________________________________________________________________
  1249.   forwarders 1.2.3.4 1.2.3.5
  1250.   ______________________________________________________________________
  1251.  
  1252.   in the named.boot file.  Also leave the root.cache file empty.  That
  1253.   will decrease the amount of IP traffic your host originates, any
  1254.   possibly speed things up.  This especially important if you're paying
  1255.   pr. byte that goes over the wire.  This has the added value of letting
  1256.   you off the one maintenance duty you have as a caching named
  1257.   maintainer; you don't have to update a empty root.cache file.
  1258.  
  1259.   8.  FAQ
  1260.  
  1261.   In this section I list some of the most frequently asked questions
  1262.   related to DNS and this HOWTO.  And the answers :-) Please read this
  1263.   section before mailing me.
  1264.  
  1265.   1. How do use DNS from inside a firewall?
  1266.  
  1267.      A couple of hints: `forwarders', `slave', and have a look in the
  1268.      literature list at the end of this HOWTO.
  1269.  
  1270.   2. How do I make DNS rotate through the available addresses for a
  1271.      service, say www.busy.site to obtain a load balancing effect, or
  1272.      similar?
  1273.  
  1274.      Make several A records for www.busy.site and use bind 4.9.3 or
  1275.      later.  Then bind will round-robin the answers.  It will not work
  1276.      with earlier versions of bind.
  1277.  
  1278.   3. I want to set up DNS on a (closed) intranet.  What do I do?
  1279.  
  1280.      You drop the cache file and just do zone files.  That also means
  1281.      you don't have to get new cache files all the time.
  1282.  
  1283.   4. My system does not have the ndc program.  What do I do?
  1284.  
  1285.      Your system then has an old, somewhat obsolete, bind installed.  If
  1286.      security is important to you: upgrade bind at once.  If not, you
  1287.      can live with it.  And instead of running ndc start you run named.
  1288.      ndc reload becomes named.reload and ndc restart becomes
  1289.      named.restart.  All of those programs are most likely in /usr/sbin.
  1290.  
  1291.   5. How do I set up a secondary name server?
  1292.  
  1293.      If the primary server has address 127.0.0.1 you put a line like
  1294.      this in the named.boot file of your secondary:
  1295.  
  1296.      ___________________________________________________________________
  1297.        secondary     linux.bogus             127.0.0.1       sz/linux.bogus
  1298.  
  1299.      ___________________________________________________________________
  1300.  
  1301.   6. I want bind running when I'm disconnected from the net.
  1302.  
  1303.      I have received this mail from Ian Clark <ic@deakin.edu.au> where
  1304.      he explains his way of doing this:
  1305.  
  1306.   I run named on my 'Masquerading' machine here. I have
  1307.   two root.cache files, one called root.cache.real which contains
  1308.   the real root server names and the other called root.cache.fake
  1309.   which contains...
  1310.  
  1311.   --------------
  1312.   ; root.cache.fake
  1313.   ; this file contains no information
  1314.   --------------
  1315.  
  1316.   When I go off line I copy the root.cache.fake file to root.cache and
  1317.   restart named.
  1318.  
  1319.   When I go online I copy root.cache.real to root.cache and restart
  1320.   named.
  1321.  
  1322.   This is done from ip-down & ip-up respectively.
  1323.  
  1324.   The first time I do a query off line on a domain name named doesn't
  1325.   have details for it puts an entry like this in messages..
  1326.  
  1327.   Jan 28 20:10:11 hazchem named[10147]: No root nameserver for class IN
  1328.  
  1329.   which I can live with.
  1330.  
  1331.   It certainly seems to work for me. I can use the nameserver for
  1332.   local machines while off the 'net without the timeout delay for
  1333.   external domain names and I while on the 'net queries for external
  1334.   domains work normally
  1335.  
  1336.   7. Where does the caching name server store it's cache? Is there any
  1337.      way I can control the size of the cache?
  1338.  
  1339.      The cache is completely stored in memory, it is not written to disk
  1340.      at any time.  Every time you kill named the cache is lost.  The
  1341.      cache is not controllable in any way.  named manages it according
  1342.      to some simple rules and that is it.  You cannot control the cache
  1343.      or the cache size in any way for any reason. If you want to you can
  1344.      ``fix'' this by hacking named.  This is however not recommended.
  1345.  
  1346.   8. Does named save the cache between restarts?  Can I make it save it?
  1347.  
  1348.      No, named does not save the cache when it dies.  That means that
  1349.      the cache must be built anew each time you kill and restart named.
  1350.      There is no way to make named save the cache in a file.  If you
  1351.      want you can ``fix'' this by hacking named.  This is however not
  1352.      recommended.
  1353.  
  1354.   9.  How to become a bigger time DNS admin.
  1355.  
  1356.   Documentation and tools.
  1357.  
  1358.   Real Documentation exists.  Online and in print.  The reading of
  1359.   several of these is required to make the step from small time DNS
  1360.   admin to a big time one.  In print the standard book is DNS and BIND
  1361.   by C. Liu and P. Albitz from O'Reilly & Associates, Sebastopol, CA,
  1362.   ISBN 0-937175-82-X.  I read this, it's excellent.  There is also a
  1363.   section in on DNS in TCP/IP Network Administration, by Craig Hunt from
  1364.   O'Reilly..., ISBN 0-937175-82-X.  Another must for Good DNS
  1365.   administration (or good anything for that matter) is Zen and the Art
  1366.   of Motorcycle Maintenance by Robert M. Prisig :-) Available as ISBN
  1367.   0688052304 and others.
  1368.  
  1369.   Online you will find stuff on  <http://www.dns.net/dnsrd/>,
  1370.   <http://www.vix.com/isc/bind/>; A FAQ, a reference manual (BOG; Bind
  1371.   Operations Guide) as well as papers and protocol definitions and DNS
  1372.   hacks (these, and most, if not all, of the rfcs mentioned below, are
  1373.   also contained in the bind distribution).  I have not read most of
  1374.   these, but then I'm not a big-time DNS admin either.  Arnt Gulbrandsen
  1375.   on the other hand has read BOG and he's ecstatic about it :-).  The
  1376.   newsgroup comp.protocols.tcp-ip.domains is about DNS.  In addition
  1377.   there are a number of RFCs about DNS, the most important are probably
  1378.   these:
  1379.  
  1380.      RFC 2052
  1381.         A. Gulbrandsen, P. Vixie, A DNS RR for specifying the location
  1382.         of services (DNS SRV), October 1996
  1383.  
  1384.      RFC 1918
  1385.         Y. Rekhter, R. Moskowitz, D. Karrenberg, G. de Groot, E. Lear,
  1386.         Address Allocation for Private Internets, 02/29/1996.
  1387.  
  1388.      RFC 1912
  1389.         D. Barr, Common DNS Operational and Configuration Errors,
  1390.         02/28/1996.
  1391.  
  1392.      RFC 1713
  1393.         A. Romao, Tools for DNS debugging, 11/03/1994.
  1394.  
  1395.      RFC 1712
  1396.         C. Farrell, M. Schulze, S. Pleitner, D. Baldoni, DNS Encoding of
  1397.         Geographical Location, 11/01/1994.
  1398.  
  1399.      RFC 1183
  1400.         R. Ullmann, P. Mockapetris, L. Mamakos, C. Everhart, New DNS RR
  1401.         Definitions, 10/08/1990.
  1402.  
  1403.      RFC 1035
  1404.         P. Mockapetris, Domain names - implementation and specification,
  1405.         11/01/1987.
  1406.  
  1407.      RFC 1034
  1408.         P. Mockapetris, Domain names - concepts and facilities,
  1409.         11/01/1987.
  1410.  
  1411.      RFC 1033
  1412.         M. Lottor, Domain administrators operations guide, 11/01/1987.
  1413.  
  1414.      RFC 1032
  1415.         M. Stahl, Domain administrators guide, 11/01/1987.
  1416.  
  1417.      RFC 974
  1418.         C. Partridge, Mail routing and the domain system, 01/01/1986.
  1419.  
  1420.